<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="/common/jsp/taglibs-nojs-nocss.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<base href="<%=basePath%>"/>

	<script type="text/javascript">
	// Example: obj = findObj("image1");
	function findObj(theObj,theDoc){
		var p,i,foundObj;
		if(!theDoc)
		theDoc=document;
		if((p=theObj.indexOf("?"))>0&&parent.frames.length){
			theDoc=parent.frames[theObj.substring(p+1)].document;
			theObj=theObj.substring(0,p);
		}
		if(!(foundObj=theDoc[theObj])&&theDoc.all)
			foundObj=theDoc.all[theObj];
		for(i=0;!foundObj&&i<theDoc.forms.length;i++)
			foundObj=theDoc.forms[i][theObj];
		for(i=0;!foundObj&&theDoc.layers&&i<theDoc.layers.length;i++)
			foundObj=findObj(theObj,theDoc.layers[i].document);
		if(!foundObj&&document.getElementById)
			foundObj=document.getElementById(theObj);
		return foundObj;
	}
	//添加一个新项目
	//读取最后一行的行号，存放在txtTRLastIndex文本框中行
	function AddSignRow(){
		var txtTRLastIndex=findObj("txtTRLastIndex",document);
		var rowID=parseInt(txtTRLastIndex.value);
		var signFrame=findObj("SignFrame",document);
		var newTR=signFrame.insertRow(signFrame.rows.length);  //添加行
		newTR.id="SignItem"+rowID;
		
		var newNameTD=newTR.insertCell(0);  //添加列：序号
		newNameTD.innerHTML=newTR.rowIndex.toString();  //添加列内容
		
		var newNameTD=newTR.insertCell(1);  //添加列:货物名称
		newNameTD.innerHTML="<input id='name_chn"+rowID+"' name='goodsOrderDetailList["+rowID+"].productName' class='names' type='text' size='45' style='width:130' />";  //添加列内容
		
		var newUnitTD=newTR.insertCell(2);  //添加列:单位
		newUnitTD.innerHTML="<input  id='name_en"+rowID+"' name='goodsOrderDetailList["+rowID+"].productUnit' class='names' type='text' size='12' style='width:100'/>";  //添加列内容 
		
		var newCountNumTD=newTR.insertCell(3);  //添加列:数据类型
		newCountNumTD.innerHTML = "<input  id='countNum"+ rowID + "' name='goodsOrderDetailList["+rowID+"].countNum'  type='text' size='12' style='width:100'/>";  //添加列内容
		
		var newPackingModeTD=newTR.insertCell(4);  //添加列:数据类型
		newPackingModeTD.innerHTML = "<input  id='packingMode"+ rowID + "' name='goodsOrderDetailList["+rowID+"].packingMode'  type='text' size='12' style='width:100'/>";  //添加列内容
		
		var newDeleteTD=newTR.insertCell(5);  //添加列:删除按钮
		newDeleteTD.innerHTML = "<div align='center' style='width:60px'><a href='javascript:void(0);' onclick=\"DeleteSignRow('SignItem" + rowID + "')\">删除</a></div>";  //添加列内容
		txtTRLastIndex.value=(rowID+1).toString();  //将行号推进下一行 
	}
	//删除指定行
	function DeleteSignRow(rowid){
		var signFrame = findObj("SignFrame",document);
		var signItem = findObj(rowid,document);
		var rowIndex = signItem.rowIndex;  //获取将要删除的行的Index
		signFrame.deleteRow(rowIndex);  //删除指定Index的行
		for(i=rowIndex;i<signFrame.rows.length;i++){  //重新排列序号，如果没有序号，这一步省略
			signFrame.rows[i].cells[0].innerHTML = i.toString();
		}
	}
	//清空列表
	function ClearAllSign(){
		if(confirm('确定要清空所有项目吗？')){
			var signFrame = findObj("SignFrame",document);
			var rowscount = signFrame.rows.length;
			for(i=rowscount - 1;i > 0; i--){  //循环删除行,从最后一行往前删除
				signFrame.deleteRow(i);
			}
			var txtTRLastIndex = findObj("txtTRLastIndex",document);  //重置最后行号为1
			txtTRLastIndex.value = "1";
			AddSignRow();  //预添加一行
		}
	}
	function check(){
		var arr = document.getElementsByTagName('INPUT');
		var str = "";
		for(var i=0;i<arr.length;i++){
			if(arr[i].className == 'names'){
				if(arr[i].value==''){
					alert("工作内容不能为空！！");
					arr[i].focus();
					return false;
				}else{
				  	str = str + arr[i].value+"^";
				}
			}
		}
		document.getElementById("myContent").value = str;
	}
	</script>

<div id="pop_up_content">
	<div class="pop_up_title images_1">
		新建送货清单
	</div>
	<div class="pop_up_body">
		<form id="thisForm" action="<%=basePath%>goodsOrder/goodsOrderAction!editGoodsOrder.action" method="post">
			<input type="hidden" value="<s:property value='form.id'/>" name="form.id"/>
			<input type="hidden" value="2" name="form.orderType"/>
			<input type="hidden" value="<s:property value='id'/>" name="form.contractId"/>
			
			<table border="0" cellpadding="0" cellspacing="0" width="600px">
				<tr style="height:22px;">
					<td class="form_input_value" >
						<span class="red">*</span>客户名称
					</td>
					<td colspan="2" >
					   <input style="width:180" id="form.customerName" name="form.customerName" type="text" value="${form.customerName}" class="required validate_forbiddenChar max_length:40">
					</td>
					
					<td class="form_input_value" >
						<span class="red">*</span>货单编码
					</td>
					<td colspan="2" >
					   <input style="width:180" id="form.orderCode" name="form.orderCode" type="text" value="${form.orderCode}" class="required validate_forbiddenChar max_length:40">
					</td>
				</tr>
				<tr style="height:22px;">
					<td class="form_input_value" >
							<span class="red">*</span>收货人
					</td>
					<td colspan="2" >
					   <input style="width:180" id="form.linkMan" name="form.linkMan" type="text" value="${form.linkMan}" class="required validate_forbiddenChar max_length:40">
					</td>
					<td class="form_input_value" >
							<span class="red">*</span>联系方式
					</td>
					<td colspan="2" >
					   <input style="width:180" id="form.linkManMode" name="form.linkManMode" type="text" value="${form.linkManMode}" class="required validate_forbiddenChar max_length:40">
					</td>
				</tr >
				<tr style="height:22px;">
					<td class="form_input_value" >
							<span class="red">*</span>收货地址
					</td>
					<td colspan="2" >
					   <input style="width:180" id="form.address" name="form.address" type="text" value="${form.address}" class="required validate_forbiddenChar max_length:40">
					</td>
				</tr >
				<tr style="height:22px;">
				</tr>
			</table>
			<div class="wbs_scroll" style="height: 180px">
				<table id="SignFrame" border="0" cellpadding="2" cellspacing="1" style="margin:0px; font-size:14px; margin-top: 10">
					<tr id="trHeader" style="height:22px;">
						<td class="form_input_value"  align="left" style="width:40">序号</td>
						<td class="form_input_value"  align="center"  style="width:130">货物名称</td>
						<td class="form_input_value"  align="center"  style="width:100">单位</td>
						<td class="form_input_value" align="center"  style="width:100" >数量</td>
						<td class="form_input_value"  align="center"  style="width:100" >包装方式</td>
						<td class="form_input_value" align="center" style="width:60" >操作</td>
					</tr>
				</table>
			</div>
			<table border="0" cellpadding="0" cellspacing="0" width="600px" >
				<tr style="height:22px;">
					<td class="form_input_value" >
						<span class="red">*</span>填表人:
					</td>
					<td colspan="2" >
					   <input style="width:180" id="form.writeUser" name="form.writeUser" type="text" value="${form.writeUser}" class="required validate_forbiddenChar max_length:40" />
					</td>
					
					<td class="form_input_value" >
						<span class="red">*</span>发货单位:
					</td>
					<td colspan="2" >&nbsp;&nbsp;
						<input style="width:180" id="form.orderUnit" name="form.orderUnit" type="text" value="${form.orderUnit}" class="required validate_forbiddenChar max_length:40" />
						<%--
						北京鼎一伟信科技发展有限公司
						 <s:property value="contractForm.projectUnit"/>
						 --%>
					</td>
				</tr>
				<tr style="height:10px;">
					<td></td>
					<td></td>
				</tr>
				
				<tr style="height:22px;">
					<td class="form_input_value" >
						<span class="red">*</span>收货人签字：
					</td>
					<td colspan="2" >
					   <input style="width:180;border-bottom-color: #000000;border-left-width: 0;border-right-width: 0;border-top-width: 0" 
					   		id="form.signUser" name="form.signUser" type="text" value="${form.signUser}" 
					   		class="required validate_forbiddenChar max_length:40">
					</td>
					
					<td class="form_input_value" >
							<span class="red">*</span>送货日期：
					</td>
					<td colspan="2" >&nbsp;&nbsp;
						 <input  readonly="readonly" onclick="WdatePicker();" style="width:180" id="form.orderTime" name="form.orderTime" type="text" value="${form.orderTime}" class="longinput required">
					   
					</td>
				</tr>
			</table>
			<table id="option" border="0" cellpadding="2" cellspacing="1" style="margin:0px; font-size:8px;">
				<tr>
					<td>
						<input type="button" id="add" name="add" value="添加新项" onclick="AddSignRow();" class="btn" onmouseout="this.className='btn'" onmousedown="this.className='btn1'" onmouseover="this.className='btn2'">
					</td>
					<td>
						<input type="button" id="clear" name="clear" value="清空" onclick="ClearAllSign();" class="btn" onmouseout="this.className='btn'" onmousedown="this.className='btn1'" onmouseover="this.className='btn2'">
					</td>
					<td>
						<input type="button" id="thisButton" name="thisButton" value="提交" class="btn" onmouseout="this.className='btn'" onmousedown="this.className='btn1'" onmouseover="this.className='btn2'">
					</td>
					<td>
						<input type="button" value="取消" class="btn" onclick="hideDialog();" onmouseout="this.className='btn'" onmousedown="this.className='btn1'" onmouseover="this.className='btn2'">
					</td>
					<td>
						<input type="hidden" id="txtTRLastIndex" name="txtTRLastIndex" value="1"/>
					</td>
					<td>
						<!-- 
						<input type="hidden" name="personLogVo.user.id" value="<s:property value="#session.user.userId"/>"/>
						 -->
					</td>
					<td>
						<input type="hidden" name="logDay" value="7"/>
					</td>
				</tr>
			</table>
			
		</form>
	</div>
</div>
<script type="text/javascript">
/* 表单提交 */
	i.formSubmit("thisButton",	//绑定的按钮id
					  "thisForm" ,   //提交的表单id
	  function(result){
		  	var jsonMsgObj=new JsonMsgObj(result);
			var  msg=jsonMsgObj.getMessage();
		    var codeId=jsonMsgObj.getCodeid();
			var isOk=jsonMsgObj.getIsok();
			if( isOk ){
			    aerouiAlert(msg);
				hideDialog();// 隐藏窗口
				window.location.reload();
			}else{		// 如果编辑失败了
			  JsManageInfoHandleException( result , function(msg , codeId , isOk){
			  		hideDialog();// 隐藏窗口
			   });
		   }
		});
</script>